/**
 * @param {number} n
 * @return {number}
 */
var countArrangement = function (n) {
  let arr = [],res=[], count = 0, visit = Array(n + 1).fill(false)
  bc(1)

  function bc(index) {
    if (arr.length == n) {
      // if(check(arr)){
      //   count++
      // }  
      res.push([...arr])
      return
    }

    for (let i = 1; i <= n; i++) {
      if(visit[i])continue
      arr.push(i)
      visit[i] = true
      bc(i + 1)
      arr.pop(i)
      visit[i] = false
    }
  }

  console.log(res);
  debugger
};

countArrangement(3)